<template>
  <div>
    <el-form ref="form" :model="sizeForm" label-width="80px" size="mini">
      <el-form-item label="客户编号">
        <el-input v-model="sizeForm.name"></el-input>
      </el-form-item>
      <el-form-item label="商品编号">
        <el-select v-model="sizeForm.proID" placeholder="请选择商品编号">
          <el-option
            v-for="i in product"
            :label="i.goodsID"
            :value="i.goodsID"
            :key="i.goodsID"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="配送员">
        <el-select v-model="sizeForm.employeeID" placeholder="请选择配送员">
          <el-option
            v-for="i in employee"
            :label="i.employeeID"
            :value="i.employeeID"
            :key="i.employeeID"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="配送时间">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="sizeForm.date"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="数量">
        <el-input-number v-model="sizeForm.num" :step="1"></el-input-number>
      </el-form-item>
      <el-form-item label="订单情况">
        <el-radio-group v-model="sizeForm.state" size="medium">
          <el-radio border label="完成"></el-radio>
          <el-radio border label="未完成"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="reset">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";
import qs from "qs";
export default {
  data() {
    return {
      sizeForm: {
        name: "",
        proID: "",
        employeeID: "",
        date: "",
        state: "",
        num: 1,
      },
      product: [],
      employee: [],
    };
  },
  methods: {
    onSubmit() {
      axios({
        url: "http://localhost:3000/addOrder",
        method: "post",
        data: qs.stringify(this.sizeForm),
      }).then(()=>{
        this.$router.push('/order')
      })
      this.$message({
          message: '创建成功！',
          type: 'success'
        });
    },
    reset() {
      this.$router.push("/order");
    },
    getOpitons() {
      return axios.get("http://localhost:3000/getPro");
    },
    getEmployee() {
      return axios.get("http://localhost:3000/getEmp");
    },
  },
  mounted() {
    axios.all([this.getOpitons(), this.getEmployee()]).then(
      axios.spread((res1, res2) => {
        this.product = res1.data;
        this.employee = res2.data;
      })
    );
  },
};
</script>

<style scoped>
</style>